using System;
using System.Collections.Generic;
using System.Web.UI;

namespace MvpFramework
{
    /// <summary>
    /// A Base class for controls that implement <see cref="IMvpView"/>
    /// </summary>
    public class MvpUserControlBase : UserControl, IMvpView
    {
        private object _presenter;
        private ValidationManager _validationManager;
        /// <summary>
        /// All the validation message controls for the page
        /// </summary>
        public IList<IValidationMessage> ValidationErrorLabels
        {
            get { return _validationManager.GetAllValidationLabels(); }
        }

        #region IMvpView Members

        /// <summary>
        /// Is this the first time the control has loaded
        /// </summary>
        public bool IsInitialLoad
        {
            get { return !IsPostBack; }
        }

        #endregion

        /// <summary>
        /// Attaches a presenter
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _presenter = this.GetPresenter();
            _validationManager = new ControlValidationManager(this);
        }

        public IValidationMessage GetValidationLabelFor(object spec)
        {
            return _validationManager.GetValidationLabelFor(spec);
        }
    }
}